import { useLocation, useNavigate, useRoutes } from 'react-router-dom';
import Login from './pages/login';
import { CustomerRouterGuard } from './components/customer-router-guard';
import { routes } from '../routes';
import { Home } from './pages/home';
import { MainLayout } from './components/MainLayout';
import ProductList from './pages/product-list';
import ProductAdd from './pages/product-add';
import Register from './pages/register';
import ProductCategory from './pages/product-category';
import zhCN from 'antd/lib/locale/zh_CN';
import { ConfigProvider } from 'antd';
import React from 'react';
export function App() {
  const location = useLocation();
  const navigate = useNavigate();
  if (location.pathname === routes.ADMIN_LOGIN) {
    return <Login />;
  }
  if (location.pathname === routes.ADMIN_REGISTER) {
    return <Register />;
  }

  //路由表
  const elements = useRoutes([
    {
      path: '/',
      element: <Home />
    }, {
      path: routes.ADMIN_HOME,
      element: <Home />
    }, {
      path: routes.ADMIN_PRODUCT_LIST,
      element: <ProductList />
    }, {
      path: routes.ADMIN_PRODUCT_ADD,
      element: <ProductAdd />
    }, {
      path: routes.ADMIN_PRODUCT_CATEGORY,
      element: <ProductCategory />
    }
  ]);

  return (
    <ConfigProvider locale={zhCN}>
      <CustomerRouterGuard />
      <MainLayout>
        {elements}
      </MainLayout>
    </ConfigProvider>
  );
}

export default App;
